package com.geektime.hello;

import cn.hutool.http.HttpRequest;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

/**
 * @Author: DRevelation
 * @Date: 2021/4/1 11:15
 * 大洋数据同步
 */
@Slf4j
@Component
public class OceanSyncUtil {

    /**
     * 内容分类同步URL
     */
    public static final String CONTENT_CLASS_URL = "http://36.7.147.222:1001/FrontPlateformServer/api/receiveFrontContentClass";

    /**
     * 海豚号同步URL
     */
    public static final String OFFICIAL_ACCOUNT_URL = "http://36.7.147.222:1001/FrontPlateformServer/api/receiveFrontOfficialAcount";

    /**
     * 内容分类同步
     *
     * @param type
     * @param cmsContentClass
     */
//    @Async
//    public void syncContentClass(Integer type, CmsContentClass cmsContentClass) {
//        JSONObject object = new JSONObject();
//        object.put("opType", type);
//        JSONObject data = new JSONObject();
//        data.put("class_id", cmsContentClass.getClassId());
//        data.put("class_name", cmsContentClass.getClassName());
//        data.put("description", cmsContentClass.getDescription());
//        object.put("data", data);
//        String result = HttpRequest.post(OceanSyncUtil.CONTENT_CLASS_URL)
//                .body(object.toJSONString())
//                .execute().body();
//        log.info("result=" + result);
//    }

    /**
     * 海豚号同步
     *
     * @param type
     * @param officialAccount
     */
//    @Async
//    public void syncOfficialAccount(Integer type, OfficialAccount officialAccount) {
//        JSONObject object = new JSONObject();
//        object.put("opType", type);
//        JSONObject data = new JSONObject();
//        data.put("official_id", officialAccount.getOfficialId());
//        data.put("official_name", officialAccount.getOfficialName());
//        data.put("official_class", officialAccount.getOfficialClass());
//        data.put("official_keyword", officialAccount.getOfficialKeyword());
//        object.put("data", data);
//        String result = HttpRequest.post(OceanSyncUtil.OFFICIAL_ACCOUNT_URL)
//                .body(object.toJSONString())
//                .execute().body();
//        log.info("result=" + result);
//    }

}
